package leetcode.offer_two_special.backtrack;

/**
 * @author mazouri
 * @create 2021-09-20 17:23
 */
public class _102_findTargetSumWays {
    int[] nums;
    int target;
    int count = 0;

    public int findTargetSumWays(int[] nums, int target) {
        this.nums = nums;
        this.target = target;
        dfs(0, 0);
        return count;
    }

    private void dfs(int sum, int level) {
        if (level == nums.length) {
            if (sum == target) count++;

            return;
        }

        dfs(sum + nums[level], level + 1);
        dfs(sum - nums[level], level + 1);
    }
}
